﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Drawing;

namespace uz.control.SingleValueEdit
{

    public class SVE_Base:TNB_Panel
    {
        public int TitleWidth { get; set; }
        public string Title { get; set; }

        public delegate void HandleValueChanged(string ValueName, string OldValue, string NewValue);

        public HandleValueChanged ValueChanged;

        public static SVE_Base CreateSingleViewEditor<T>(int TitleWidth, string Title)
        {
            SVE_Base sve = (SVE_Base)typeof(T).Assembly.CreateInstance(typeof(T).FullName);
            sve.TitleWidth = TitleWidth;
            sve.Title = Title;

            return sve;
        }

        public void OnValueChanged(string OldValue, string NewValue)
        {
            if (ValueChanged != null)
            {
                ValueChanged(Title, OldValue, NewValue);
            }
        }

        public override void InitPanel()
        {
            Label lab = new Label();
            //lab.BorderStyle = BorderStyle.FixedSingle;
            lab.Width = TitleWidth;
            lab.AutoSize = false;
            lab.Text = Title + "：";
            lab.TextAlign = ContentAlignment.MiddleLeft;
            lab.Dock = DockStyle.Left;
            

            InitControl();
            Panel.Controls.Add(lab);

        }

        public virtual void InitControl()
        {

        }

        public override int HandleAreaWidth
        {
            get
            {
                return 0;
            }
        }

        public override Rectangle GetHandleRect()
        {
            Rectangle rect= base.GetHandleRect();
            return new Rectangle(rect.Left, rect.Height, 0, 0);
        }

    }
}
